<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 计算乘除法，输入两个数，按钮 1 计算乘法，按钮 2 计算除法 -->
    第一个数：<input type="text" id="num1" /><br />
    第二个数：<input type="text" id="num2" />
    <p>
      <button onclick="cacl(mul)">相乘</button>
      <button onclick="cacl(div)">相除</button>
    </p>
    <p>结果：<input type="text" id="result" /></p>
    <script>
      function cacl(func) {
        var result = document.getElementById('result')
        var num1 = parseInt(document.getElementById('num1').value)
        var num2 = parseInt(document.getElementById('num2').value)
        if (isNaN(num1) || isNaN(num2)) {
          alert('请输入数字')
        }
        result.value = func(num1, num2)
      }
      function mul(num1, num2) {
        return num1 * num2
      }
      function div(num1, num2) {
        if (num2 === 0) {
          alert('除数不能为0')
          return ''
        }
        return num1 / num2
      }
    </script>
  </body>
</html>
